<div class="editor-default-node4-header-medium" data-template="t_4_3">
	<img src="https://urc-thumb.oss-cn-beijing.aliyuncs.com/resource-temp/1725514076938section-ico4.png">1.3.5
	使用gsql客户端连接数据库
</div>
<p style="text-align:justify;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	gsql客户端是openGauss数据库自带的命令行客户端工具，具有连接数据库、执行SQL语句和执行<span class="font_normal">&nbsp;</span>
	<kw res-type="keyWord" class="keyWord_e font_normal" id="kw_a_PKJZKT6S3C">元命令</kw><span
		class="font_normal">&nbsp;</span>等功能。
</p>
<p class="p-fold"><span class="td-fold"><input id="check_1734401355859" type="checkbox"><span
			class="foldTitle td-fold td-fold"><span class="td-fold td-fold"><span
					class="font_blue3"><b>gsql客户端连接参数</b></span></span></span><label for="check_1734401355859"
			class="check-in-fold"
			style="background-image: url(&quot;https://dbook.hep.com.cn/admin/css/img/upICO.png&quot;); background-repeat: no-repeat; background-color: initial; background-size: 30px;"></label><label
			for="check_1734401355859" class="check-out-fold"
			style="background-image: url(&quot;https://dbook.hep.com.cn/admin/css/img/downICO.png&quot;); background-repeat: no-repeat; background-color: initial; background-size: 30px;"></label><span
			class="element-fold td-fold td-fold"><span
				class="font_kaiti">&nbsp;&nbsp;&nbsp;&nbsp;gsql工具使用-d参数指定目标数据库名、-U参数指定数据库用户名、-h参数指定主机名、-p参数指定端口号信息、-r参数开启命令补全功能、-W参数指定密码。若未指定数据库名称，则使用初始化时默认生成的数据库名称；若未指定数据库用户名，则默认使用当前操作系统用户作为数据库用户名；若未指定主机名，则默认连接本地数据库；若未指定密码，则需要根据交互提示输入密码。</span></span></span>
</p>
<p>  <b>1. 基于管理员账户使用gsql客户端连接数据库</b></p>
<p style="text-align:justify;">&nbsp; &nbsp; &nbsp; &nbsp;openGauss的命令行访问方式主要是通过自带的gsql客户端进行的，使用gsql客户端需要切换到操作系统的omm用户。
</p>
<p><span class="font_blue2">[root@node1
		~]# su - omm</span></p>
<p style="text-align:justify;"><span class="font_blue2"><span class="font_black">&nbsp; &nbsp; &nbsp; &nbsp;
			使用管理员账户登录数据库，如图1-3-4所示。命令如下：</span><br></span></p>
<p><span class="font_blue2">[omm@node1 ~]$
		gsql -d postgres -p 15400 -U omm -r</span></p>
<p style="text-align:center;" id="pic_p_FKB69FYT3C"><img res-type="image" class="insertPic cres" id="FKB69FYT3C"
		src="https://dbook.hep.com.cn/api/v2/resource/preview?id=FKB69FYT3C" style="max-width:100%;"><br><span
		class="insertPicTitle" id="pic_title_FKB69FYT3C">图1-3-4 使用内置管理员账户omm登录数据库</span></p>
<p><span class="font_blue2"></span></p>


<p>  <b>2. 基于其他账户使用gsql客户端连接数据库</b></p>
<p style="text-align:justify;">&nbsp; &nbsp; &nbsp;
	&nbsp;默认情况下，openGauss数据库系统禁止使用数据库管理员omm进行远程连接，同时初始状态下没有可供访问的其他用户。因此需要使用数据库管理员omm创建一个用户，才能以该用户身份进行本地和远程访问。
</p>
<p style="text-align:justify;">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;执行下面的SQL语句创建用户myroot，密码为myroot_123，为了方便后续操作同时给予该用户管理员权限，如轮播图1-3-5(a)所示。命令如下：
</p>
<p><span class="font_blue2">openGauss=#
		CREATE USER myroot WITH SYSADMIN PASSWORD "myroot_123";&nbsp;</span></p>
<p style="text-align:justify;">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果myroot用户已存在，可通过如下命令给予其管理员权限，如轮播图1-3-5(b)所示。</p>
<p><span class="font_blue2">openGauss=#
		ALTER USER myroot SYSADMIN;&nbsp;</span></p>
<p style="text-align:justify;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建用户myroot后，输入”<span
		class="font_blue2">\q</span>“退出gsql客户端。</p>
<div class="editor-default-node7-header-small" data-template="t_7_4">练一练</div>
<p id="span_h5_F37ZY2563J"><iframe src="https://dbook.hep.com.cn/api/v2/resource/preview?id=F37ZY2563J" width="100%"
		height="600px" frameborder="no" border="0" res-type="iframe" class="insertH5 cres" id="F37ZY2563J"></iframe></p>
<p style="text-align:justify;">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;接下来使用用户myroot的身份使用gsql客户端连接数据库，并根据提示手动输入myroot用户的密码，输入密码时系统自动隐藏了密码，如轮播图1-3-1(c)所示。命令如下：
</p>
<p><span class="font_blue2">[omm@node1 ~]$
		gsql -d postgres -p 15400 -U myroot -r&nbsp;</span></p>
<p><span class="font_blue2">Password for
		user myroot:&nbsp;</span></p>
<p><span class="font_blue2">…

		&nbsp;&nbsp;</span></p>
<p><span class="font_blue2">openGauss=&gt;</span></p>
<p><span class="font_blue2"></span></p>
<div class="swiper-container swiper-initialized swiper-horizontal swiper-pointer-events swiper-backface-hidden">
	<div class="swiper-wrapper" id="swiper-wrapper-9f7f8d2c4a862b1a" aria-live="polite"
		style="transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;">
		<div class="swiper-slide swiper-slide-active" style="width: 688px;" role="group" aria-label="1 / 3"><img
				res-type="image" style="width:auto;max-width:100%;max-height:400px;" class=" cres" id="F3A7EFYVKC"
				src="https://dbook.hep.com.cn/api/v2/resource/preview?id=F3A7EFYVKC">
			<h6 class="tuIntro">(a) 创建myroot用户</h6>
		</div>
		<div class="swiper-slide swiper-slide-next" style="width: 688px;" role="group" aria-label="2 / 3"><img
				res-type="image" style="width:auto;max-width:100%;max-height:400px;" class=" cres" id="FKUHEFZTKJ"
				src="https://dbook.hep.com.cn/api/v2/resource/preview?id=FKUHEFZTKJ">
			<h6 class="tuIntro">(b) 给予myroot用户管理员权限</h6>
		</div>
		<div class="swiper-slide" style="width: 688px;" role="group" aria-label="3 / 3"><img res-type="image"
				style="width:auto;max-width:100%;max-height:400px;" class=" cres" id="F3D7EPZTKC"
				src="https://dbook.hep.com.cn/api/v2/resource/preview?id=F3D7EPZTKC">
			<h6 class="tuIntro">(c) 使用其他账户登录数据库</h6>
		</div>
	</div>
	<div class="swiper-scrollbar" style="width: 100%;"></div>
	<div class="swiper-pagination swiper-pagination-clickable swiper-pagination-bullets swiper-pagination-horizontal">
		<span class="swiper-pagination-bullet swiper-pagination-bullet-active" tabindex="0" role="button"
			aria-label="Go to slide 1" aria-current="true"></span><span class="swiper-pagination-bullet" tabindex="0"
			role="button" aria-label="Go to slide 2"></span><span class="swiper-pagination-bullet" tabindex="0"
			role="button" aria-label="Go to slide 3"></span></div>
	<div class="swiper-button-prev swiper-button-disabled" tabindex="-1" role="button" aria-label="Previous slide"
		aria-controls="swiper-wrapper-9f7f8d2c4a862b1a" aria-disabled="true"></div>
	<div class="swiper-button-next" tabindex="0" role="button" aria-label="Next slide"
		aria-controls="swiper-wrapper-9f7f8d2c4a862b1a" aria-disabled="false"></div><span class="swiper-notification"
		aria-live="assertive" aria-atomic="true"></span>
</div>
<p style="text-align:center;">轮播图1-3-1 基于其他账户使用gsql客户端连接数据库</p>
<p style="text-align: center;" id="video_p_PK6RF9X3JJ"><span class="td" id="video_td_span_PK6RF9X3JJ"><input
			id="check_PK6RF9X3JJ" type="checkbox" class="insertVideoCheck"><span class="videoTitlepc-new"
			id="video_title_span_PK6RF9X3JJ"
			style="background: url(https://dbook.hep.com.cn/admin/css/img/vedio_pic.png) no-repeat 5px 7px;background-size: 45px;">视频1-3-3
			使用gsql客户端连接数据库</span><label for="check_PK6RF9X3JJ" class="check-in-new"
			style="background-image: url(&quot;https://dbook.hep.com.cn/admin/css/img/upICO.png&quot;); background-repeat: no-repeat; background-color: initial; background-size: 30px;"></label><label
			for="check_PK6RF9X3JJ" class="check-out-new"
			style="background-image: url(&quot;https://dbook.hep.com.cn/admin/css/img/downICO.png&quot;); background-repeat: no-repeat; background-color: initial; background-size: 30px;"></label><span
			class="element-new"><video res-type="video" class="insertVideo cres" id="PK6RF9X3JJ"
				src="https://dbook.hep.com.cn/api/v2/resource/preview?id=PK6RF9X3JJ" controls="" width="100%"
				poster="https://dbook.hep.com.cn/api/v2/resource/cover/preview?id=PK6RF9X3JJ"></video><br><span
				class="insertVideoTitle" id="video_title_PK6RF9X3JJ">视频1-3-3 使用gsql客户端连接数据库</span></span></span></p>

<div class="editor-default-node7-header-small" data-template="t_7_4">练一练</div>
<p id="span_h5_F3L8LE56KC"><iframe src="https://dbook.hep.com.cn/api/v2/resource/preview?id=F3L8LE56KC" width="100%"
		height="600px" frameborder="no" border="0" res-type="iframe" class="insertH5 cres" id="F3L8LE56KC"></iframe></p>